package cn.wyf.demo.service.impl;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

import javax.annotation.Resource;

import cn.wyf.demo.mapper.PersonMapper;
import cn.wyf.demo.mapper.PersonMapper1;
import cn.wyf.demo.model.Person;
import cn.wyf.demo.model.PersonExample;
import cn.wyf.demo.service.PersonService;

@Service("PersonService")
class PersonServiceImpl implements PersonService {

    @Resource
    public JdbcTemplate jdbcTemplate;

    @Resource
    public PersonMapper personMapper;

//    @Autowired
//    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
//        this.jdbcTemplate = jdbcTemplate;
//    }

    public List<Person> getAllperson() {
        String SQL = "select * from person";
        List<Person> persons = jdbcTemplate.query(SQL, new PersonMapper1());
        System.out.println(persons);
        return persons;
    }



    public int addPerson(String name, Integer age) {
        String sql = "INSERT INTO person(name,age) VALUE (?,?)";
        int update = jdbcTemplate.update(sql, name, age);
        return update;
    }

    public Person getPersonByid(Integer id) {
        Person person = personMapper.selectByPrimaryKey(id);
        return person;
    }

    public void updatePerson(Person person) {
        System.out.println(person);
        personMapper.updateByPrimaryKey(person);
    }

    public List<Person> testGetPerson(PersonExample personExample) {
        return personMapper.selectByExample(personExample);
    }

    public List<Person> queryForList(Person person) {
        return personMapper.queryForList(person);
    }
}